######################################################################
# Check for sanity to avoid later confusion

ifneq ($(words $(CURDIR)),1)
 $(error Unsupported: GNU Make cannot build in directories containing spaces, build elsewhere: '$(CURDIR)')
endif

######################################################################
ifeq ($(VERILATOR_ROOT),)
VERILATOR = verilator
else
export VERILATOR_ROOT
VERILATOR = $(VERILATOR_ROOT)/bin/verilator
endif
SRCV = 
SRC_DIR = tests
SRCSV = $(SRC_DIR)/sim_test.sv
SRCSV2 = $(SRC_DIR)/sim_test2.sv
TOP = sim_test
SRCCPP = main.cpp

VFLAGS = --binary --build --trace --assert --timing -j 4 -Wall
VCPPFLAGS = -cc --exe --build
default: $(SRCSV) $(SRCCPP)
	@echo "-- Verilator sim_test simple example"
	@echo "-- VERILATE & BUILD --------"
	$(VERILATOR) $(VCPPFLAGS) $(VFLAGS) -top $(TOP) $^
	@echo "-- RUN ---------------------"
	obj_dir/V$(TOP)
	@echo "-- DONE --------------------"
	@echo "Note: Once this example is understood, see examples/make_tracing_c."
	@echo "Note: See also https://verilator.org/guide/latest/examples.html"


.PHONY: sim lint

lint: $(SRCSV2)
	$(VERILATOR) -sv --lint-only --assert --trace --timing $^

sim: $(SRCSV2)
	$(VERILATOR) $(VCPPFLAGS) $(VFLAGS) -top $(TOP) $^

###-cc --exe --build -j 4  --assert --trace --timing $^

.PHONY: sim1
sim1: $(SRCSV)
	$(VERILATOR) $(VFLAGS) -top $(TOP) $^

### $ verilator --binary test.sv && ./obj_dir/Vtest

run:
	obj_dir/V$(TOP)

.PHONY: vlg

vlg: $(SRCV)
	iverilog $^

### verilator --binary -j 4 -Wall -top sva_svtb f_t1.v 
######################################################################

maintainer-copy::
clean mostlyclean distclean maintainer-clean::
	-rm -rf obj_dir *.log *.dmp *.vpd core
